The Traveling Salesman Problem (TSP) and Hamiltonian Path/Cycle problems are closely related, but they are not the same thing.
In a travelling salesman problem with 9 cities, the goal is to find the shortest possible route that starts at City A, visits each of the remaining eight cities exactly once, and returns to City A.
The number of possible directed tours is given by:
P(n) = (n − 1)!
For nine cities:
P(9) = 8! = 40,320
In an undirected TSP, a route and its reverse direction represent the same path. To remove these duplicates, the number of unique tours is:
U(n) = (n − 1)! / 2
For nine cities:
U(9) = 8! / 2 = 20,160
This means there are 20,160 unique undirected tours when reverse paths are treated as identical.
Click any cell to edit its weight. Use 1e9 to mark a forbidden transition.